<%@ taglib prefix="C" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 山有木兮木有枝
  Date: 2021/12/1
  Time: 21:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <!-- 包含头部信息用于适应不同设备 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 包含 bootstrap 样式表 -->
    <link rel="stylesheet" href="https://apps.bdimg.com/libs/bootstrap/3.2.0/css/bootstrap.min.css">
    <!-- 可选: 包含 jQuery 库 -->
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <!-- 可选: 合并了 Bootstrap JavaScript 插件 -->
    <script src="https://apps.bdimg.com/libs/bootstrap/3.2.0/js/bootstrap.min.js"></script>




    <style>
        .btn-file > input {
            position: absolute;
            top: 0;
            right: 0;
            width: 100%;
            height: 100%;
            margin: 0;
            font-size: 23px;
            cursor: pointer;
            filter: alpha(opacity=0);
            opacity: 0;

            direction: ltr;
        }

        .fileinput .thumbnail > img {
            max-height: 100%;
        }



        .fileinput.input-group > * {
            position: relative;
            z-index: 2;
        }


        .row {
            margin-bottom: 30px;
            margin-right: 0 !important;
            margin-left: 0 !important;
        }

        .form-group {
            margin-bottom: 30px;
        }

        .submit {
            margin-left: 30px;
        }

        .modal-btns {
            text-align: center;
        }

    </style>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div>
            <ol class="breadcrumb">
                <li><a href="${pageContext.request.contextPath}/main/gomain"  class="btn btn-primary btn-sm" role="button"><span class="glyphicon glyphicon-home pull-right" aria-hidden="true"></span>&nbsp;&nbsp; 主&nbsp;&nbsp; 页</a></li>
                <li class="active">用户管理</li>
                <li><a href="${pageContext.request.contextPath}/user/findUserAll">用户管理</a></li>
                <li class="active">用户编辑</li>
            </ol>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-8 col-lg-offset-2">
            <%--            ${pageContext.request.contextPath}/article/addArticle?currentPage=${currentPage}&rows=${rows}--%>
            <form class="form-horizontal" action="#" method="post">

                <input value="${user.userId}" type="hidden" name="userId">
                <div class="form-group">
                    <label for="userName" class="col-lg-2 control-label">用户名</label>
                    <div class="col-lg-10">
                        <input type="text" class="form-control" id="userName" name="userName" placeholder="输入用户名" value="${user.userName}">
                    </div>
                </div>

                <div class="form-group">
                    <label for="userPwd" class="col-lg-2 control-label">修改密码</label>
                    <div class="col-lg-10">
                        <input type="password" class="form-control" id="userPwd" name="userPwd" placeholder="输入密码" value="${user.userPwd}">
                    </div>
                </div>

                <div class="form-group">
                    <label for="twoUserPwd" class="col-lg-2 control-label">确定密码</label>
                    <div class="col-lg-10">
                        <input type="password" class="form-control" id="twoUserPwd" name="twoUserPwd" placeholder="再次输入密码" value="${user.userPwd}">
                        <span id="twoUserPwdMsg"></span>
                    </div>
                </div>

                <div class="form-group">
                    <label for="userTrueName" class="col-lg-2 control-label">真实姓名</label>
                    <div class="col-lg-10">
                        <input type="text" class="form-control" id="userTrueName" name="userTrueName" placeholder="输入您的真实姓名" value="${user.userTrueName}">
                    </div>
                </div>

                <!-- 演示初始化下拉列表的功能 -->
                <div class="form-group">
                    <label for="userSex" class="col-lg-2 control-label">性别</label>
                    <div class="col-lg-10">
                        <select class="form-control" name="userSex" id="userSex">
                            <c:if test="${user.userSex=='男'}">
                                <option value="男" selected>男</option>
                                <option value="女">女</option>
                            </c:if>
                            <c:if test="${user.userSex=='女'}">
                                <option value="男" >男</option>
                                <option value="女" selected>女</option>
                            </c:if>

                        </select>
                    </div>
                </div>

                <!-- 演示初始化下拉列表的功能 -->
                <div class="form-group">
                    <label for="roleId" class="col-lg-2 control-label">角色</label>
                    <div class="col-lg-10">
                        <select class="form-control" name="roleId" id="roleId">
                            <c:forEach items="${roles}" var="role">
                                <c:if test="${role==user.roleId}">
                                    <option value="${role.roleId}" selected>${role.roleName}</option>
                                </c:if>
                                <c:if test="${role!=user.roleId}">
                                    <option value="${role.roleId}">${role.roleName}</option>
                                </c:if>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label for="userPhone" class="col-lg-2 control-label">电话号码</label>
                    <div class="col-lg-10">
                        <input type="text" class="form-control" id="userPhone" name="userPhone" placeholder="输入您的电话号码" value="${user.userPhone}">
                    </div>
                </div>

                <div class="form-group">
                    <label for="userAddr" class="col-lg-2 control-label">地址</label>
                    <div class="col-lg-10">
                        <input type="text" class="form-control" id="userAddr" name="userAddr" placeholder="输入您的地址" value="${user.userAddr}">
                    </div>
                </div>


                <div class="modal-btns">
                    <button type="button" class="btn btn-primary submit" id="button">修 改</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    let pwdFlag=true;
    $("#twoUserPwd").blur(function (){

        if($("#userPwd").val().trim()===$(this).val().trim()){
            pwdFlag=true
            $("#twoUserPwdMsg").text("两次输入正确").css("color","green")
        }else {
            $("#twoUserPwdMsg").text("两次密码不一直").css("color","red")
            pwdFlag=false
        }
    }).focus(function (){
        $("#twoUserPwdMsg").text("")
        pwdFlag=false
    })

    $("#button").click(function (){
        let formDate=new FormData($("form")[0]);
        if(pwdFlag){
            $.ajax({
                url:"${pageContext.request.contextPath}/user/updateUser",
                type:"post",
                data:formDate,
                cache:false,
                async:false,
                contentType:false,
                processData:false,
                success:function (flag){
                    alert(flag)
                    window.location.href="${pageContext.request.contextPath}/user/findUserAll"
                }
            })
        }else {
            alert("密码有误！")
        }
    })

</script>
</body>
</html>
